//
//  CommonDataListViewController.m
//  Utils
//
//  Created by enghou on 2018/4/14.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "CommonDataListViewController.h"
#import "LocalPersistent.h"
@interface CommonDataListViewController ()

@end

@implementation CommonDataListViewController

-(NSString *)orgId{
    return [[LocalPersistent sharedInstance]contentForKey:@"orgId"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.cellClass) {
        UINib *nib = [UINib nibWithNibName:self.cellClass bundle:[NSBundle mainBundle]];
        [self.tableView registerNib:nib forCellReuseIdentifier:self.cellClass];
    }
    [self beginRefresh];
}

-(NSDictionary *)param{
    NSDictionary *param = @{@"page":[NSString stringWithFormat:@"%li",(long)self.page],@"rows":@"10"};
    return param;
}

-(void)beginRefresh{
    [self beginLoading];
    [[NetWorkerManager sharedInstance]getListWithPath:self.path param:[self param] itemModelClsName:self.modelClsName successBlock:^(BaseModel *model) {
        [self endLoading];
        if (model.success) {
            [self refreshSuccessWithModel:model];
        }else{
            [self commonFailBlockWithModel:model];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
}

-(void)loadNext{
    [self beginLoading];
    [[NetWorkerManager sharedInstance]getListWithPath:self.path param:[self param] itemModelClsName:self.modelClsName successBlock:^(BaseModel *model) {
        [self endLoading];
        if (model.success) {
            [self loadMoreSuccessWithModel:model];
        }else{
            [self commonFailBlockWithModel:model];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
}

#pragma mark - UITableViewDelegate And DataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellClass];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
